cimport numpy as cnp
cimport cython

cdef extern from "<nmmintrin.h>":
    ctypedef float __m128
    __m128 _mm_loadu_ps(float *a)
    __m128 _mm_mul_ps(__m128 a, __m128 b)
    void _mm_storeu_ps(float *a, __m128 b)

cdef avx_mul_ps(float* array1, float* array2, float* dst):
    cdef:
        __m128 vec1 = _mm_loadu_ps(array1)
        __m128 vec2 = _mm_loadu_ps(array2)
        __m128 result = _mm_mul_ps(vec1, vec2)
    _mm_storeu_ps(dst, result)


@cython.boundscheck(False)
@cython.wraparound(False)
@cython.initializedcheck(False)
def avx_mul(cnp.ndarray[cnp.float32_t, ndim=1] src1,
            cnp.ndarray[cnp.float32_t, ndim=1] src2,
            cnp.ndarray[cnp.float32_t, ndim=1] dst) -> None:
    cdef:
        float* src1_ptr = <float*>src1.data  # noqa
        float* src2_ptr = <float*>src2.data  # noqa
        float* dst_ptr = <float*>dst.data  # noqa
    avx_mul_ps(src1_ptr, src2_ptr, dst_ptr)  # noqa